// components/order-list/index.js
const app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    orderList: {
      type: Array,
      value: []
    },
    orderStatus: {
      type: Number,
      value: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    statusHandle(e){
     const orderStatus= e.currentTarget.dataset.orderStatus
     const orderNo= e.currentTarget.dataset.orderNo
      console.log("statusHandle"+orderStatus)
      console.log("statusHandle"+orderNo)
      if(orderStatus==0){
        app.wxRequest('POST', '/order/createAgain?orderNo='+orderNo, null, (res) => {
          if (200 == res.code) {
            console.log("继续支付订单成功")
            if('WECHAT_PAY'===res.data.status){
              this.initiatePayment(res.data.result.jsConfig)
            }
          }else{
            app.showMsg(res.msg);
          }
        }, (err) => {
            app.showMsg(err.errMsg);
        })
      }
    },
    initiatePayment(data){
      wx.requestPayment({
        timeStamp: data.timeStamp,
        nonceStr: data.nonceStr,
        package: data.package,
        signType: 'MD5',
        paySign: data.paySign,
        success: res => {
          this.setData({
            payResult: '支付成功'
          });
          wx.switchTab({
            url: '/pages/order/order'
          }) 
        },
        fail: error => {
          wx.showToast({
            title: '用户取消支付',
            icon: 'error',
            duration: 1000
          })
          setTimeout(()=>{
            wx.switchTab({
              url: '/pages/order/order'
            }) 
          },1000)
          
        }
      });
    },
    openOrderDetail() {
      console.log("打开订单明细页面")
      // wx.reLaunch({
      //   url: '/pages/orderDetail/orderDetail',
      // })
    },
    confirmReceipt(e) {
      const orderId = e.currentTarget.dataset.orderId
      console.log("orderId" + orderId)

      console.log("wx.openBusinessView" + wx.openBusinessView)
     

      wx.openBusinessView({
        businessType: 'weappOrderConfirm',
        extraData: {
          
          transaction_id: '4200002113202401227943881922'
        },
        success(res) {
          //dosomething
          console.log("1212"+res)
        },
        fail() {
          //dosomething
          console.log("88888"+res)
        },
        complete() {
          //dosomething
        }
      });
      //拉起确认收货组件
      if (wx.openBusinessView) {
        wx.openBusinessView({
          businessType: 'weappOrderConfirm',
          extraData: {
            merchant_id: '1230000109',
            merchant_trade_no: '1234323JKHDFE1243252',
            transaction_id: '420123123123123123123'
          },
          success() {
            //dosomething
          },
          fail() {
            //dosomething
          },
          complete() {
            //dosomething
          }
        });
      } else {
        //引导用户升级微信版本
      }

    }
  }
})